import axios from "axios";
import nProgress from "nprogress";
import "nprogress/nprogress.css";
import store from "@/store";

const request = axios.create({
  baseURL: process.env.VUE_APP_API,
  timeout: 10000,
})

request.interceptors.request.use(

  (config)=>{
    nProgress.start()
    config.headers.userTempId = store.state.user.userTempId
    return config
  },
  (error)=>{
    nProgress.done()
   return Promise.reject(error.message)
  }
)

request.interceptors.response.use(
  (response)=>{
    nProgress.done()
    if (response.data.code === 200 ){
      // console.log(response.data.data,1111)
      return response.data.data
    }
    return Promise.reject({message:response.data.message})
  },
  (error)=>{
    nProgress.done()
    return Promise.reject(error.message)
  }
)

export default request